package crp.core.workflow.domain.events;

import crp.core.workflow.domain.models.WorkflowInstanceEntity;
import crp.core.workflow.domain.models.WorkflowModelEntity;
import crp.core.workflow.domain.models.WorkflowTaskEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.util.Objects;

@Getter
@Builder
@AllArgsConstructor
public class WorkflowTaskStarted {
    private final WorkflowInstanceEntity instance;
    private final WorkflowTaskEntity previousTask;
    private final WorkflowTaskEntity task;

    public WorkflowModelEntity getModel() {
        return instance.getModel();
    }

    public String getTopic() {
        return getModel().getTopic();
    }

    public boolean autocomplete() {
        return Objects.isNull(previousTask) && task.getContext().isAutocomplete();
    }
}
